const { DataTypes } = require("sequelize");

const seq = require("../db/seq");
const Record = require("./record.model");
// 创建模型(Model zd_user -> 表 zd_users)
const Information = seq.define(
  "information",
  {
    // id 会被sequelize自动创建, 管理
    info_img: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "封面图片",
    },
    info_title: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "资讯标题",
    },
    info_content: {
      type: DataTypes.TEXT,
      allowNull: false,
      comment: "资讯内容",
    },
    record_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: "记录id,存储点赞、收藏、浏览数据",
    },
  },
  {
    paranoid: true,
  }
);
Information.belongsTo(Record, {
  foreignKey: "record_id",
  as: "record_info",
});
// 强制同步数据库(创建数据表)
// Information.sync({ force: true });

module.exports = Information;
